# -*- coding: utf-8 -*-
"""Resource Pool"""

import logging
log = logging.getLogger(__name__)
import transaction

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# AttrObj
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

class AttrObj(object):
    def __init__(self,aname="unsetAttr",avalue="unsetValue",adoc=""):
        self.name=aname
        self.value=avalue
        self.doc=adoc

    def __repr__(self):
        return "AttrObj(name=%s,value=%s,doc=%s)" % (self.name,self.value,self.doc)

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# AttrContainer
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

class AttrContainer(object):
    def __new__(cls, *args, **kwds):
#        print "AttrContainer.__new__", args, kwds
        return object.__new__(cls)

    def __init__(self):
        pass
    
    def getAttr(self,name):
        for i in self.attr:
            if i.name==name:
                return i.value
        return None

    def setAttr(self,name,value):
        for i in self.attr:
            if i.name==name:
                i.value=value
                return
        newattr=self.AttrClass(name,value)
        self.attr.append(newattr)

    def setAttrDoc(self,name,doc):
        for i in self.attr:
            if i.name==name:
                i.doc=doc
                return
        newattr=self.AttrClass(name,"",doc)
        self.attr.append(newattr)

    def getAttrDoc(self,name):
        for i in self.attr:
            if i.name==name:
                return i.doc
        return None

    def setAttrDoc(self,name,doc):
        raise NotImplementedError
